#-*- coding:utf-8 -*-
import json
import zmq

def test():
    context = zmq.Context()
    socket = context.socket(zmq.REP)
    
    socket.bind("tcp://*:9081")
    while True:
        recv_msg = socket.recv()
        socket.send("ok")
        print json.loads(recv_msg)['message']

    
def zmq_sender(msg, host, port):
    context = zmq.Context()
    #Only byte string is acceptable or will receive TypeError
    message = str(msg)
    # Socket to talk to server
    socket = context.socket(zmq.REQ)
    dest = "tcp://" + host + ":" + str(port)
    socket.connect(dest)
    socket.send(message)
    recv_msg = socket.recv()
    print recv_msg
    socket.close()
    print("socket close")

    
    
    